<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * create category browse page
 * get: category.tpl.php
 * used from category.page.php
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2012
 * @author     Norbert Gebert
 * @license    GPL3
 */
$file = 'module/function/category.pagination.func.php';
if (is_file($file))
	include $file;
$result = db::getInstance()->rawQuery("SELECT category_id, category_name, category_active, " .
	"category_order, category_top FROM category WHERE category_top = '0'" .
	" ORDER BY category_order");

$refPage->assign('page_titel', _('Product category settings'));
$refPage->assign('table_summary', _('This table gives a overview of the Categorys'));
$refPage->assign('category_id', _('ID'));
$refPage->assign('category_name', _('Category-Name'));
$refPage->assign('category_order', _('Order'));
$refPage->assign('category_activ', _('Activ'));
$refPage->assign('category_article', _('Article'));

$buffer = array();
$buffer = sortCategorys($result, true);

// Set datarows to display
if (!isset($_SESSION['pageC']))
	$_SESSION['pageC'] = 1;
if (ceil(count($buffer) / CATEGORY_LIST) < $_SESSION['pageC'])
	$_SESSION['pageC'] --;
if ($_SESSION['pageC'] <= 0)
	$_SESSION['pageC'] = 1;
$pageFirst = ($_SESSION['pageC'] * CATEGORY_LIST) - CATEGORY_LIST + 1;
$pageLast = $_SESSION['pageC'] * CATEGORY_LIST;
getPagination($refPage, count($buffer));
$counter = 0;

// Create table-array and html-code
$data = array();

foreach ($buffer as $datax)
{
	$counter ++;

	if ($counter < $pageFirst)
		continue;

	if ($counter > $pageLast)
		break;

	$category_namex = '<a href="index2.php?page=' . $page . '&sub=' . $subpage .
		'&id=' . $datax['category_id'] .
		'&func=edit">' . $datax['category_name'] . '</a>';

	if ($datax['category_order'] === 1)
	{
		$category_orderx = $datax['category_order'] .
			'<img src="template/images/page.article/top1.gif">';
	}
	else
	{
		$category_orderx = $datax['category_order'] .
			'<a href="index2.php?page=article&sub=category&top=' .
			$datax['category_top'] . '&order=' . $datax['category_order'] . '">' .
			'<img src="template/images/page.article/arrowup1.gif"></a>';
	}

	$category_article = '<a href="index2.php?page=article&sub=article&filterId=' .
		$datax['category_id'] . '">' . _('List Article') . '</a>';

	$category_activex = '<a href="index2.php?page=article&sub=category&id=' .
		$datax['category_id'] . '&active=1">';

	if ($datax['category_active'] === '0')
	{
		$category_activex .= '<img src="template/images/page.article/notactive.gif"></a>';
	}
	else
	{
		$category_activex .= '<img src="template/images/page.article/isactive.gif"></a>';
	}

	$data[] = array('category_set' => '<input type="checkbox" name="marker[]" ' .
	 ' value="' . $datax['category_id'] . '" />',
	 'category_idx' => $datax['category_id'],
	 'category_namex' => $category_namex,
	 'category_orderx' => $category_orderx,
	 'category_activx' => $category_activex,
	 'category_articlex' => $category_article,);
	$refPage->assign('data', $data);
}

$refPage->assign('btnDelete',
	'<input type="submit" name="submit" id="delete" value="' .
	_('Delete') . '" />');

$refPage->assign('formStart', 'index2.php?page=article&sub=category&func=12');

$refPage->assign('btnNew',
	'<input type="submit" name="submit" id="copy" value="' .
	_('New') . '" />');

$refPage->assign('btnCopy',
	'<input type="submit" name="submit" id="copy" value="' .
	_('Copy') . '" />');

$refPage->assign('pagetitel', _('Pagetitel') . ':');

$refPage->assign('active', _('Active') . ':');
$refPage->addtpl('content', '/' . $page . '/' . $subpage . '.tpl.php');
?>